package cn.yunhe.controller;

import cn.yunhe.entity.User;
import cn.yunhe.services.IUserService;
import cn.yunhe.services.impl.UserService;
import cn.yunhe.utils.BaseAction;
import lombok.Data;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Data
public class UserAddAction extends BaseAction {
    private String uname;
    private String upwd;

    public String execute() throws IOException {
        HttpServletResponse response = getResponse();
        PrintWriter out = response.getWriter();
        IUserService iUserService = new UserService();
        User user = new User(uname, upwd);
        int row = iUserService.addUser(user);
        if (row > 0) {
            String  msg = "T";
            out.print(msg);
            return "success";
        } else {
            getMapRequest().put("msg","添加用户失败,请<a href='userList.html'>重试<a/>");
            return "error";
        }

    }
}
